# -*- coding:utf-8 -*-
f = open('testFile', 'r+')
str = f.read(1)
print(str)
print(f.readline())

for line in f:
    print(line, end='')
f.close()

f = open('testFile', 'r+')
lists = list(f)
print(lists)  # ['你好 世界1\n', '\n', '你好 世界2\n', '你好 世界3\n', '你好 世界4']
f.close()

f = open('testFile', 'r')
lists = f.readlines()
print(lists)  # ['你好 世界1\n', '\n', '你好 世界2\n', '你好 世界3\n', '你好 世界4']
f.close()

# write
fw = open('testFile2', 'a')
print(
    fw.write('this is my test\n')
)
print(fw.tell())
fw.close()

# seek
f = open('testFile3', 'rb+')
f.write(b'0123456789abcdef')
print(f.tell())
f.seek(5)
print(f.read())  # b'56789abcdef'
f.close()

# with
with open('testFile3', 'r') as f:
    read_data = f.read()


f.read()
